<%@page import="java.util.List"%>
<%@page import="cn.edu.svtcc.domain.Product"%>
<%@page import="cn.edu.svtcc.dao.UserDAOimp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>商品列表</title>
<!--设置标签图标-->
<link href="../favicon.ico" rel="/shortcut icon">
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet"
	href="../css/goods_list.css">
<link rel="stylesheet" href="../css/pageStyle.css">
<link rel="stylesheet" href="../css/footer.css">
<style>
/* 在原有的 <style> 标签中添加或在外部CSS文件中定义 */

/* 表格样式 */
table {
    width: 100%;
    border-collapse: collapse;
    margin: auto;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

th, td {
    padding: 15px;
    text-align: center;
    border: 1px solid #ddd;
}

th {
    background-color: #007bff;
    color: white;
}

/* 按钮样式 */
.btn {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    background-color: #28a745;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn:hover {
    background-color: #218838;
}

.btn-icon {
    margin-right: 5px; /* 为图标留出空间 */
}

/* 删除按钮样式 */
.btnDelete {
    background-color: #c82333;
}

.btnDelete:hover {
    background-color: #721c24;
}

/* 分页样式 */
.page {
    text-align: center;
    margin-top: 20px;
}

.page a {
    padding: 8px 15px;
    border: 1px solid #007bff;
    border-radius: 4px;
    background-color: #007bff;
    color: white;
    text-decoration: none;
    transition: background-color 0.3s, border-color 0.3s;
    margin: 0 5px;
}

.page a:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}6
</style>
</head>
<body>
	<c:if test="${sessionScope.admin!=null }">
		<table>
			<tr>
				<th>商品名</th>
				<th>库存</th>
				<th>价格</th>
				<th>类别</th>
				<th>供应商</th>
				<th>操作</th>
			</tr>
			<c:forEach items="${Goods }" var="good">
				<tr>
					<td style="text-align: center;">${good.getPname() }</td>
					<td style="text-align: center;">${good.getStuck() }</td>
					<td style="text-align: center;">${good.getPprice() }</td>
					<td style="text-align: center;">${good.getCategoryName() }</td>
					<td style="text-align: center;">${good.getProviderName() }</td>
					<td style="text-align: center;"><input type="button"
						class="btn btn-icon" value="编辑" id="edit"
						onClick="editGood('${good.getPid()}')">&nbsp;&nbsp; <input
						type="button" class="btn btn-icon" value="删除" id="delete"
						onClick="deleteGood('${good.getPid()}')"></td>
				</tr>
			</c:forEach>
		</table>
		<div class="page">
			<c:if test="${pageIndex>1 }">
				<a href="AdminGoodsListServlet?pageIndex=${pageIndex-1}">上一页</a>
			</c:if>
			当前是第${pageIndex }页
			<c:if test="${pageIndex<pageNum+1 }">
				<a href="AdminGoodsListServlet?pageIndex=${pageIndex+1}">下一页</a>
			</c:if>
			<a id="back" href="adminIndex.jsp">返回</a>
		</div>
	</c:if>


	<jsp:include page="../footer.jsp"></jsp:include>



	<script src="../js/jquery.min.js"></script>
	<script src="../js/layer/layer.js"></script>
	<script>
    function move(){
    	window.location.href="AdminGoodsListServlet";
    }
    function editGood(id){
    	window.location.href="AdminGetGoodToEditServlet?id="+id;
    }
    function deleteGood(id){
    	layer.confirm('确认要删除该产品？', {
    		  btn: ['删除','取消'] //按钮
    		}, function(){
    			$.post("AdminDeleteGoodServlet",{
    				id:id
    			},function(data){
    				if(data=="ok"){
    					layer.msg('删除成功', {icon: 1});
    					setTimeout("move()",2000);
    				}
    				if(data=="error"){
    					layer.msg('删除失败,文件可能已被删除', {icon: 2});
    				}
    			})
    		  
    		}, function(){
    	
    		  });
    	
    }
	</script>
</body>
</html>